import { 
  User, 
  UserRole, 
  Project, 
  ProjectStatus, 
  Application, 
  ApplicationStatus, 
  MatchRecord, 
  Statistics 
} from '@/types'

// 模拟用户数据
export const mockUsers: User[] = [
  {
    id: '1',
    username: 'enterprise1',
    role: UserRole.ENTERPRISE,
    name: '华为技术有限公司',
    email: 'hr@huawei.com',
    phone: '0755-12345678',
    organization: '华为技术有限公司',
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-01T00:00:00Z'
  },
  {
    id: '2',
    username: 'supervisor1',
    role: UserRole.SUPERVISOR,
    name: '张教授',
    email: 'zhang@sysu.edu.cn',
    phone: '020-12345678',
    department: '计算机科学与技术学院',
    researchDirection: ['人工智能', '机器学习', '计算机视觉'],
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-01T00:00:00Z'
  },
  {
    id: '3',
    username: 'student1',
    role: UserRole.STUDENT,
    name: '李同学',
    email: 'li@sysu.edu.cn',
    phone: '020-87654321',
    department: '计算机科学与技术学院',
    researchDirection: ['人工智能', '深度学习'],
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-01T00:00:00Z'
  },
  {
    id: '4',
    username: 'admin',
    role: UserRole.ADMIN,
    name: '管理员',
    email: 'admin@sysu.edu.cn',
    phone: '020-11111111',
    organization: '中山大学研究生院',
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-01T00:00:00Z'
  }
]

// 模拟项目数据
export const mockProjects: Project[] = [
  {
    id: '1',
    title: '基于深度学习的图像识别系统开发',
    enterpriseId: '1',
    enterpriseName: '华为技术有限公司',
    researchDirection: ['人工智能', '深度学习', '计算机视觉'],
    description: '开发一套基于深度学习的图像识别系统，能够准确识别和分类各种图像内容。',
    requirements: '熟悉Python、TensorFlow/PyTorch，有图像处理经验，具备良好的算法设计能力。',
    deadline: '2024-12-31',
    budget: 50000,
    status: ProjectStatus.PUBLISHED,
    createdAt: '2024-01-15T00:00:00Z',
    updatedAt: '2024-01-15T00:00:00Z'
  },
  {
    id: '2',
    title: '新型材料在电子器件中的应用研究',
    enterpriseId: '1',
    enterpriseName: '华为技术有限公司',
    researchDirection: ['新材料', '电子工程', '物理化学'],
    description: '研究新型材料在电子器件中的应用，探索提高器件性能的新途径。',
    requirements: '材料科学、电子工程或相关专业背景，有实验室研究经验。',
    deadline: '2024-10-31',
    budget: 40000,
    status: ProjectStatus.PUBLISHED,
    createdAt: '2024-02-01T00:00:00Z',
    updatedAt: '2024-02-01T00:00:00Z'
  },
  {
    id: '3',
    title: '网络安全威胁检测与防护系统',
    enterpriseId: '1',
    enterpriseName: '华为技术有限公司',
    researchDirection: ['网络安全', '信息安全', '机器学习'],
    description: '开发网络安全威胁检测与防护系统，提高网络安全防护能力。',
    requirements: '网络安全、信息安全或计算机科学专业，熟悉网络协议和机器学习算法。',
    deadline: '2024-11-30',
    budget: 45000,
    status: ProjectStatus.PUBLISHED,
    createdAt: '2024-02-15T00:00:00Z',
    updatedAt: '2024-02-15T00:00:00Z'
  }
]

// 模拟申请数据
export const mockApplications: Application[] = [
  {
    id: '1',
    projectId: '1',
    projectTitle: '基于深度学习的图像识别系统开发',
    applicantId: '2',
    applicantName: '张教授',
    applicantRole: UserRole.SUPERVISOR,
    researchPlan: '计划采用最新的Transformer架构，结合计算机视觉技术，开发高精度的图像识别系统。',
    resume: '中山大学计算机学院教授，在人工智能领域有15年研究经验，发表论文50余篇。',
    status: ApplicationStatus.APPROVED,
    createdAt: '2024-01-20T00:00:00Z',
    updatedAt: '2024-01-25T00:00:00Z'
  },
  {
    id: '2',
    projectId: '1',
    projectTitle: '基于深度学习的图像识别系统开发',
    applicantId: '3',
    applicantName: '李同学',
    applicantRole: UserRole.STUDENT,
    researchPlan: '作为研究生，希望在导师指导下参与该项目，学习深度学习在图像识别中的应用。',
    resume: '中山大学计算机学院研究生，研究方向为人工智能，有Python和机器学习基础。',
    status: ApplicationStatus.PENDING,
    createdAt: '2024-01-22T00:00:00Z',
    updatedAt: '2024-01-22T00:00:00Z'
  }
]

// 模拟匹配记录
export const mockMatchRecords: MatchRecord[] = [
  {
    id: '1',
    projectId: '1',
    projectTitle: '基于深度学习的图像识别系统开发',
    enterpriseId: '1',
    enterpriseName: '华为技术有限公司',
    applicantId: '2',
    applicantName: '张教授',
    applicantRole: UserRole.SUPERVISOR,
    status: 'confirmed',
    enterpriseConfirm: true,
    applicantConfirm: true,
    adminConfirm: true,
    createdAt: '2024-01-25T00:00:00Z',
    updatedAt: '2024-01-30T00:00:00Z'
  }
]

// 模拟统计数据
export const mockStatistics: Statistics = {
  totalProjects: 3,
  totalApplications: 2,
  totalMatches: 1,
  projectsByDiscipline: {
    '人工智能': 1,
    '新材料': 1,
    '网络安全': 1
  },
  applicationsByStatus: {
    'pending': 1,
    'approved': 1,
    'rejected': 0,
    'matched': 0
  },
  matchesByMonth: {
    '2024-01': 1,
    '2024-02': 0,
    '2024-03': 0
  }
}

// 模拟API服务类
export class MockApiService {
  // 获取用户信息
  static async getUserInfo(userId: string): Promise<User | null> {
    return new Promise((resolve) => {
      setTimeout(() => {
        const user = mockUsers.find(u => u.id === userId)
        resolve(user || null)
      }, 300)
    })
  }

  // 获取项目列表
  static async getProjects(params?: any): Promise<{ data: Project[], total: number }> {
    return new Promise((resolve) => {
      setTimeout(() => {
        let filteredProjects = [...mockProjects]
        
        if (params?.keyword) {
          filteredProjects = filteredProjects.filter(p => 
            p.title.includes(params.keyword) || 
            p.description.includes(params.keyword)
          )
        }
        
        if (params?.discipline) {
          filteredProjects = filteredProjects.filter(p => 
            p.researchDirection.includes(params.discipline)
          )
        }
        
        if (params?.enterpriseName) {
          filteredProjects = filteredProjects.filter(p => 
            p.enterpriseName.includes(params.enterpriseName)
          )
        }
        
        resolve({
          data: filteredProjects,
          total: filteredProjects.length
        })
      }, 300)
    })
  }

  // 获取申请列表
  static async getApplications(params?: any): Promise<{ data: Application[], total: number }> {
    return new Promise((resolve) => {
      setTimeout(() => {
        let filteredApplications = [...mockApplications]
        
        if (params?.status) {
          filteredApplications = filteredApplications.filter(a => a.status === params.status)
        }
        
        resolve({
          data: filteredApplications,
          total: filteredApplications.length
        })
      }, 300)
    })
  }

  // 获取统计数据
  static async getStatistics(): Promise<Statistics> {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(mockStatistics)
      }, 300)
    })
  }

  // 创建项目申请
  static async createApplication(application: Omit<Application, 'id' | 'createdAt' | 'updatedAt'>): Promise<Application> {
    return new Promise((resolve) => {
      setTimeout(() => {
        const newApplication: Application = {
          ...application,
          id: Date.now().toString(),
          createdAt: new Date().toISOString(),
          updatedAt: new Date().toISOString()
        }
        mockApplications.push(newApplication)
        resolve(newApplication)
      }, 300)
    })
  }

  // 更新申请状态
  static async updateApplicationStatus(applicationId: string, status: ApplicationStatus): Promise<boolean> {
    return new Promise((resolve) => {
      setTimeout(() => {
        const application = mockApplications.find(a => a.id === applicationId)
        if (application) {
          application.status = status
          application.updatedAt = new Date().toISOString()
          resolve(true)
        } else {
          resolve(false)
        }
      }, 300)
    })
  }
}
